//视频时间格式化 （参数t以秒为单位）
function timeFormat(t){
	if(t <= 0){return '00:00';}
	var m = Math.floor(t / 60);
	m < 10 && (m = '0' + m);
	return m + ':' + (t % 60 / 100).toFixed(2).slice(-2);
}

//日期格式化函数
function formatDate(v){
	if(!v || '' == v) {
		return '';
	}
	return Ext.Date.format(new Date(v),'Y-m-d H:i:s');
}

//数字格式化函数，保留整数
function toFixed0(v){
	var a = Number(v).toFixed(0);
	return a == 'NaN' ? v : a;
}

//数字格式化函数，保留两位
function toFixed2(v){
	var a = Number(v).toFixed(2);
	return a == 'NaN' ? v : a;
}

//百分比格式化
function percentage(v){
	var a = v*100;
	return a == 'NaN' ? "" : toFixed2(a) +"%";
}

function downLoad(url,params){
	params = params||{};
	if(params.html){
		params.html = params.html.replace(/&nbsp;/g,'$_nbsp_$');
	}
//	var iframe = Ext.query('#down-load')[0];
	var form = '<form action="'+url+'" method="post" target="_self">';
	for ( var key in params) {
		form+= "<input type='text' name='"+key+"' value='"+params[key]+"'>";
	}
	form += '</form>';
	var dform = $(form);
	dform.ready(function(){
		dform.submit();
	});
}

var _wdcs = ['日','一','二','三','四','五','六'];

function show_sys_time(){
	var _time = Ext.Date.format(new Date(),'Y年m月d日 周 H:i:s');
	_time = _time.replace("周","周"+_wdcs[Ext.Date.format(new Date(),'w')]);
	$('#desk-time').text(_time);
	setTimeout(show_sys_time,1000);
}

/**
 * 选择树节点的所有父节点
 * @param node
 */
function checkAllParent(node){
	if(!node.parentNode.isRoot()){
		node.parentNode.set('checked',true);
		checkAllParent(node.parentNode);
	}
}
/**
 * 树形菜单过滤
 * @param tree
 * @param v
 */
function treeFilter(tree,v){
	tree.expandAll(function(){
		tree.getRootNode().cascadeBy(function(node){
			var el = Ext.get(tree.view.getNode(node));
			if(el){
				if(v == ''){
					el.setDisplayed(true);
				}
				else{
					var _v = v.toLowerCase();
					var value = node.data.text ? node.data.text.toLowerCase() : '';
					el.setDisplayed(value.indexOf(v) >= 0);
				}
			}
		});
	});

}


function preventDefaultMenu(dom){
	$(dom).bind('contextmenu',function() { return false; }); 
	try {
		dom.attachEvent('onmousedown', function(){
			if(2 === event.button) {
				dom.setCapture();
			}
		});
		dom.attachEvent('onmouseup', function () {
			dom.releaseCapture();
		});
		dom.oncontextmenu = function () {
			return false;
		};
	} catch (e) {
		// TODO: handle exception
	}
}